﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace ProjetSMA
{
    static class Program
    {
        const int LENGTH = 32;
        /// <summary>
        /// Point d'entrée principal de l'application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            Model.Element[,] matrice = new Model.Element[LENGTH, LENGTH];
            Random rd = new Random();
            int cpt = 0;

            for (int i = 0; i < LENGTH; i++)
            {
                for (int j = 0; j < LENGTH; j++)
                {
                    Model.Element loc_element = new Model.Element(i,j, "");
                    loc_element.I = i;
                    loc_element.J = j;

                    matrice[i, j] = loc_element;


                    cpt++;

                   
                }
            }
           
            
            for (int i = 0; i < LENGTH; i++)
            {
                for (int j = 0; j < LENGTH; j++)
                {
                    matrice[i, j].InitialisationNeighbors(matrice, LENGTH);
                }
            }

            cpt = 0;
            Random rdd = new Random();
          
            for (int i = 0; i < LENGTH; i++)
            {
                for (int j = 0; j < LENGTH; j++)
                {

                    if (cpt % rdd.Next(1, LENGTH * 3) == 0)
                        matrice[i, j].Height = rdd.Next(3, 13);

                    cpt++;


                }
            }

            for (int i = 0; i < LENGTH; i++)
            {
                for (int j = 0; j < LENGTH; j++)
                {

                    if (matrice[i, j].Height>1)
                        InitialisationHeight(matrice[i, j]);

                    cpt++;


                }
            }


            display(matrice);

            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static void InitialisationHeight(Model.Element par_element)
        {
            if (par_element.Height > 1 )
            {

               for (int i = 0; i < par_element.Neighboors.Count; i++)
               {
                   if (par_element.Neighboors[i].Height < par_element.Height)
                   {
                       par_element.Neighboors[i].Height = par_element.Height - 1;
                       InitialisationHeight(par_element.Neighboors[i]);
                   }
               }
            }
        }


        static int recur(Model.Element[,] matrx, int h)
        {
            if (h == 1)
                return h;
            else
            {
                //matrice[i, j].InitialisationHeight(matrice[i, j].Height);
                return recur(matrx, h - 1);
            }
        }

        static void display(Model.Element[,] par_m)
        {
            Console.WriteLine(""); Console.WriteLine("");
            for (int i = 0; i < LENGTH; i++)
            {
                Console.WriteLine();
                for (int j = 0; j < LENGTH; j++)
                {
                    if (par_m[i, j].Height > 9)
                     Console.Write(par_m[i, j].Height+" ");
                    else
                        Console.Write(par_m[i, j].Height + "  ");
                }
            }
            Console.WriteLine(""); Console.WriteLine("");
        }
    }
}
